package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDADefectWhyCountRequestController {

    def commentService

    def index() {
        def result = ResultModel.getResultModel()
        try {
            def PDADefectWhyCountRequest = Utils.parseStr2Json(params?.PDADefectWhyCountRequest)
//            PDADefectWhyCountRequest=  Utils.parseStr2Json(PDADefectWhyCountRequest)

            def MACHINENAME = params.MACHINENAME ?: "aa"

            Header header = new Header(TRANSACTIONID: Utils.getUUID(), MESSAGENAME: "PDADefectWhyCountRequest", MACHINENAME: MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header, body: PDADefectWhyCountRequest, aReturn: aReturn)
//            result = commentService.getJsonByTopic2Queue(requestModel,"sendmqname","returnmqname",true,responseXml)

            result = commentService.getJsonByTopic2Queue_1(requestModel, "jms.topic.PDA.TO.CIM", "jms.queue.CIM.PDA.Send", false, false)

        } catch (Exception e) {
            result.put(ResultModel.ServerErrorFlag, true)
            result.put(ResultModel.Code, ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg, ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data, e.getMessage())
        } finally {
            render Utils.getFormatString(result)
        }
    }

    def responseXml = """
<MESSAGE>
<HEADER>
  <TRANSACTIONID>ce56f6fc-e5d7-4d7c-b6db-abf66cf9716e</TRANSACTIONID>
  <MESSAGENAME>PDADefectWhyCountResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>1</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-03-14 16:44:01.724</EVENTTIME>
</HEADER>
<BODY>
  <EQPID>DB-447</EQPID>
  <USERNAME>IE05</USERNAME>
  <DEFECTSUM>35</DEFECTSUM>
</BODY>
<RETURN>
  <RETURNCODE>0</RETURNCODE>
  <RETURNMESSAGE>返回各个工序的报废原因及数量</RETURNMESSAGE>
</RETURN>
</MESSAGE>
"""
}